﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//using System.Windows.Forms;

namespace Entities.Utilities
{
    public class Log
    {
        public static string LogFileLocation = "./Log/Log.txt";

        public Log()
        {
            //LogFileLocation = System.Web.HttpContext.Current.Server.MapPath(LogFileLocation);
            
            LogFileLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, LogFileLocation);
            /*
            if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(LogFileLocation)))
            {
                //string file = ConfigurationManager.AppSettings["LOGFILEPATH"];
                string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

                LogFileLocation = Path.Combine(baseDirectory, LogFileLocation);
                if (!File.Exists(FILEPATH))
                {
                    throw (new Exception());
                }
            }*/
            //LogFileLocation = Path.Combine(Application.StartupPath, LogFileLocation);
        }

        /// <summary>
        /// Log an entry
        /// </summary>
        /// <param name="entry">
        /// Entry value
        /// </param>
        public void LogEntry(string entry)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(LogFileLocation, true))
                {
                    sw.WriteLine(DateTime.Now.ToString() + "-" + entry);
                }
            }
            catch (Exception exception)
            {
                throw exception;
                /* Do Nothing */
            }
        }
    }
}
